/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pessoas.log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import pessoas.interfaces.Log;
import pessoas.serializacao.serializacaoArquivo;
import pessoas.serializacao.serializacaoXML;

/**
 *
 * @author Bush
 */
public class ConfiguracoesLog {
    private static ConfiguracoesLog configLog;
    private Log log;
    private String tipoLog;
    private File caminhoLog = new File("src/pessoas/data/configLog.txt");
    
    public ConfiguracoesLog() throws FileNotFoundException {
        if(tipoLog().equals("xml")){
            log = new serializacaoXML();
        }else if(tipoLog().equals("txt")){
            log = new serializacaoArquivo();
        }
    }
    
    public Log getLog() {
        return log;
    }

    public String getTipoLog() throws FileNotFoundException {
        return tipoLog = tipoLog();
    }   
        
    private String tipoLog() throws FileNotFoundException{
        Scanner scan = new Scanner(caminhoLog);
        String linha = "";
        while (scan.hasNextLine()) {
            linha += scan.nextLine();
        }
        return linha;
    }
    
    public void alterarTipo(String tipo) throws IOException{
        FileWriter w = new FileWriter(caminhoLog, false);
        BufferedWriter bf = new BufferedWriter(w);
        bf.write(tipo);
        bf.close();
    }
    
    
    
}
